package git.bankview.wl.common;

import java.util.*;
import java.text.*;
import java.sql.*;

import laya.semi.process.*;

import git.bankview.sl.db.*;

import org.apache.log4j.Logger;

public class SqlDateParser
	implements IGenericClassActivity
{
	private static Logger log = Logger.getLogger(SqlDateParser.class);

	public void execute(IProcessContext oCtx)
		throws Exception
	{
		String[] vParam = oCtx.getActivityParameter().split(":");
		String fmt = vParam[0];
		SimpleDateFormat sdf = new SimpleDateFormat(fmt);
		String errPrefix = vParam[1];
		
		for (int i = 2; i < vParam.length; ++i)
		{
			String[] vDestSrc = vParam[i].split("=");
			String oStr = (String)oCtx.getField(vDestSrc[1]);
			java.sql.Date oSrc = null;
			
			if (!(null == oStr || 0 == oStr.trim().length()))
			{
				try
				{
					oSrc = new java.sql.Date(sdf.parse(oStr).getTime());
				}
				catch(ParseException e)
				{
					throw new ActivityException(vDestSrc[1], errPrefix + vDestSrc[1]);
				}
			}
			
			oCtx.setField(vDestSrc[0], oSrc);
		}
	}
}
